﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Web;
using System.Net;
using System.IO;
namespace Demo
{
    public class DataAdd2 : DataAdd
    {
        public DataAdd2() : base('B')
        {
        }

        public DataAdd2(int? entryId) : base('B', entryId)
        {
        }

        protected override bool TryValidateAge(DateTime birthDate, DateTime testDate, out string message)
        {
            if (testDate < birthDate)
            {
                message = "測試日期不可早於出生日期。";
                return false;
            }

            var ageInMonths = CalculateAgeInMonths(birthDate, testDate);
            const int minMonths = 4 * 12;
            const int maxMonths = 7 * 12;

            if (ageInMonths < minMonths)
            {
                message = "該測試僅適用四歲以上兒童，請確認出生日期或測試日期。";
                return false;
            }

            if (ageInMonths > maxMonths)
            {
                message = "該測試僅適用七歲以內兒童，請確認出生日期或測試日期。";
                return false;
            }

            message = string.Empty;
            return true;
        }
    }
}
